<?php 
	// (1)求最后剩下的数字
	$s = Remain(10,4);
	echo join($s);
	function Remain($n,$m){
		$arr = range(1,$n);
		$i = 1;
		while (count($arr)>1) {
			foreach ($arr as $k => $v) {
				if ($i == $m) {
					unset($arr[$k]);
					$i = 1;
				}else{
					$i++;
				}
			}
		}
		return $arr;
	}
	echo "<br>";

	//（2）将数组分为三组，每组的和尽量相等
	$list = [1,2,3,4,5,6];
	$result = mathTwo($list);
	print_r($result);
	function mathTwo($list){
		//对数组进行倒叙排列
		rsort($list);
		//取出每组的最大值
		$result = [
			[array_shift($list)],
			[array_shift($list)],
			[array_shift($list)]
		];
		for ($i=0; $i <count($list) ; $i++) { 
			$result[2][] = $list[$i];
			$sum = array_sum($result[2]);
			if ($sum>array_sum($result[0])) {
				$result = [
					$result[2],
					$result[0],
					$result[1]
				];
			}elseif ($sum>array_sum($result[1])) {
				$result = [
					$result[0],
					$result[2],
					$result[1]
				];
			}

		}
		return $result;
	}
	echo "<br>";

	// （3）返回数组内数字可以组成的最大值
	$list = [1,2,3];
	$result = Findmax($list);
	print_r($result);
	function Findmax($list){
		$arr = [];
		foreach ($list as $k => $v) {
			$arr[] = [$v];
		}
		//通过递归进行操作
		$res = Digui($arr);
		rsort($res);
		return $res[0];
	}
	function Digui($arr){
		$start = array_shift($arr);
		$next = array_shift($arr);
		$zu = [];
		foreach ($start as $k => $v) {
			foreach ($next as $j => $jv) {
				$zu[] = $start[$k].$next[$j];
				$zu[] = $next[$j].$start[$k];
			}
		}
		if (empty($arr)) {
			return $zu;
		}else{
			array_unshift($arr,$zu);
			return Digui($arr);
		}
	}
	echo "<br>";

	// (4)银行问题
	echo bank(
		[9.01, 9.10, 9.20, 9.21, 9.22],
		[0.30, 0.18, 0.22, 0.47, 0.11]
	);
	function bank($a_time,$p_time){
		//定义一个窗口数组
		$win = [];
		$num =count($a_time);
		$wait_time = 0;
		for ($i=0; $i <$num ; $i++) { 
			if (count($win)>4) {
				$wait_time = $a_time[$i] + $p_time[$i];
			}
		}

	}
 ?>